package com.zlzxm.shoesmarket.view.activity;

import android.content.Context;
import android.content.Intent;
import android.view.WindowManager;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.google.android.material.tabs.TabLayout;
import com.zlzxm.shoesmarket.R;
import com.zlzxm.shoesmarket.util.ZViewHelp;
import com.zlzxm.shoesmarket.view.fragment.FMAddNote;
import com.zlzxm.shoesmarket.view.widget.simpleead.OnLeftclicklistener;
import com.zlzxm.shoesmarket.view.widget.simpleead.SimpleHead;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

/**
 * CREATE BY zlzxm ON 2021/5/17
 * <br> 增加记账
 */
public class ACAddNote extends BaseActivity{

    private TabLayout tabLayout;

    public static void start(Context context) {
        Intent starter = new Intent(context, ACAddNote.class);
        context.startActivity(starter);
    }

    @Override
    protected void initView() {
        super.initView();
        setContentView(R.layout.ac_add_note);
        SimpleHead simpleHead = ZViewHelp.findById(this,R.id.head);
        simpleHead.setTitle("记账");
        simpleHead.setOnItemclicklistener(new OnLeftclicklistener() {
            @Override
            public void onLeftItemClick() {
                finish();
            }
        });

        tabLayout = ZViewHelp.findById(this,R.id.tabLayout);

        ViewPager viewPager = ZViewHelp.findById(this,R.id.viewPager);

        viewPager.setAdapter(new Mypager(getSupportFragmentManager()));

        tabLayout.setupWithViewPager(viewPager);


    }

    @Override
    protected void initViewModule() {
        super.initViewModule();
    }

    @Override
    protected void initData() {
        super.initData();
    }

    class Mypager extends FragmentPagerAdapter{

        private List<Fragment> pager = new ArrayList<>();

        public Mypager(@NonNull @NotNull FragmentManager fm) {
            super(fm,BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
            pager.add( FMAddNote.newInstance(FMAddNote.type_out));
            pager.add( FMAddNote.newInstance(FMAddNote.type_in));
        }

        @NonNull
        @NotNull
        @Override
        public Fragment getItem(int position) {
            return pager.get(position);
        }

        @Override
        public int getCount() {
            return pager.size();
        }

        @Nullable
        @org.jetbrains.annotations.Nullable
        @Override
        public CharSequence getPageTitle(int position) {
            return position == 0?"支出":"收入" ;
        }
    }


}
